package jp.idahopotato.adapter;

import java.util.List;

import jp.idahopotato.activity.ResultDetailActivity;
import jp.idahopotato.activity.ResultListActivity;
import jp.idahopotato.bean.Result;
import jp.matome.activity.R;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;

/**
 * 検索結果のリスト表示用アダプター
 * @author hiroki
 *
 */
public class ResultSetAdapter extends ArrayAdapter<Result> {
	private LayoutInflater mInflater;
	private TextView resultNum;
	private TextView aiueo;
	private TextView abcde;
	private Button detailButton;
	private ResultListActivity rlContext = null;
	private static final int SHOSW_CALC = 0;

	public ResultSetAdapter(Context context, List<Result> objects) {
		super(context, 0, objects);
		// TODO 自動生成されたコンストラクター・スタブ
		mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		rlContext = (ResultListActivity) context;
	}

	@Override
	public View getView(int position, View convertView, final ViewGroup parent) {
		// TODO 自動生成されたメソッド・スタブ
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.resultitem, null);
		}
		final Result item = this.getItem(position);
		if(item != null){
			resultNum = (TextView)convertView.findViewById(R.id.resultNum);
			resultNum.setText(item.getResultName());
			aiueo = (TextView)convertView.findViewById(R.id.aiueo);
			aiueo.setText(item.getHead());
			abcde = (TextView)convertView.findViewById(R.id.abcde);
			abcde.setText(item.getArm());
			detailButton = (Button)convertView.findViewById(R.id.detailButton);
			detailButton.setOnClickListener(new OnClickListener() {
				public void onClick(View v) {
					Intent intent = new Intent(rlContext, ResultDetailActivity.class);
					intent.putExtra("SELECTED_ITEM", item);
					rlContext.startActivityForResult(intent, SHOSW_CALC);
				}
			});
		}
		return convertView;
	}


}
